package com.handtransaction.dao;


import com.handtransaction.entity.TOGoods;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface GoodsTipOffDao {
    //添加举报记录
    @Insert("insert into goodstipoff value(null,#{tgid},#{tuid},#{treason},CURRENT_TIMESTAMP)")
    int createTOGoods(TOGoods toGoods);

    //删除举报记录 -- 举报记录tid
    @Delete("delete from goodstipoff where tid=#{tid}")
    int deleteTOGoodsBytid(Integer tid);

    //删除多条举报记录 -- 已下架商品
    @Delete("delete from goodstipoff where tgid=#{tgid}")
    int deleteTOGoodsBytgid(Integer tgid);

    //查询举报记录 --- 通过举报记录id
    @Select("select * from goodstipoff where tid=#{tid}")
    @Results(id = "TOGoodsMap" , value={
            @Result(id = true,property = "tid",column = "tid"),
            @Result(property = "tgid",column = "tgid"),
            @Result(property = "tuid",column = "tuid"),
            @Result(property = "treason",column = "treason"),
            @Result(property = "totime",column = "totime"),
            @Result(property = "togoods",column = "tgid",
                    one = @One(select = "com.handtransaction.dao.GoodsDao.queryGoodBygid",fetchType = FetchType.LAZY)),
            @Result(property = "touser",column = "tuid",
                    one = @One(select = "com.handtransaction.dao.UserDao.queryUserByuid",fetchType = FetchType.LAZY))
    })
    TOGoods queryTOGoodsBytid(Integer tid);


    //查询所有举报记录
    @Select("select * from goodstipoff")
    @ResultMap("TOGoodsMap")
    List<TOGoods> queryAllTOGoods();




}
